package cst.a819wh.recyclerview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myadapter;
    List<ArticleBean> list;
    private void init(){
        recyclerView = (RecyclerView) findViewById(R.id.fuckYou);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);

        recyclerView.setHasFixedSize(true);

        list = getData();
        myadapter = new MyAdapter(this);
        myadapter.setList(list);
        recyclerView.setAdapter(myadapter);

    }

    private List<ArticleBean> getData(){
        List<ArticleBean> list = new ArrayList<ArticleBean>();
        ArticleBean art,art2;

        art = new ArticleBean();
        art.setArticleID(1);
        art.setTitle("标题一");
        art.setImgid(R.drawable.f1);
        art.setTime("123456789时间");
        art.setDescription("描述一");
        list.add(art);

        art2 = new ArticleBean();
        art2.setArticleID(2);
        art2.setTitle("标题二");
        art2.setImgid(R.drawable.f2);
        art2.setTime("123456789时间");
        art2.setDescription("描述二");
        list.add(art2);

        art2 = new ArticleBean();
        art2.setArticleID(3);
        art2.setTitle("标题三");
        art2.setImgid(R.drawable.f3);
        art2.setTime("123456789时间");
        art2.setDescription("描述三");
        list.add(art2);

        art2 = new ArticleBean();
        art2.setArticleID(4);
        art2.setTitle("标题四");
        art2.setImgid(R.drawable.f4);
        art2.setTime("123456789时间");
        art2.setDescription("描述四");
        list.add(art2);

        art2 = new ArticleBean();
        art2.setArticleID(5);
        art2.setTitle("标题五");
        art2.setImgid(R.drawable.f5);
        art2.setTime("123456789时间");
        art2.setDescription("描述四");
        list.add(art2);

        art2 = new ArticleBean();
        art2.setArticleID(6);
        art2.setTitle("标题六");
        art2.setImgid(R.drawable.f6);
        art2.setTime("123456789时间");
        art2.setDescription("描述六");
        list.add(art2);

        art2 = new ArticleBean();
        art2.setArticleID(7);
        art2.setTitle("标题七");
        art2.setImgid(R.drawable.f1);
        art2.setTime("123456789时间");
        art2.setDescription("描述七");
        list.add(art2);

        return list;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
}
